#include "queue.h"

QL *createQueueList()
{
    QL *queue = (QL *)malloc(sizeof(QL));
    ERROR_CHECK(NULL, queue, "malloc create");
    queue->front = queue->rear = 0;
}
int isEmpty(QL *queue)
{
    if (NULL == queue)
    {
        puts("NULL queue");
        exit(1);
    }

    return queue->rear == queue->front ? 1 : 0;
}
int isFull(QL *queue)
{
    if (NULL == queue)
    {
        puts("NULL queue");
        exit(1);
    }

    return queue->rear == queue->front -1  ? 1 : 0;
}

void enQueue(QL *queue, type val)
{
    if (isFull(queue))
    {
        puts("full queue");
        exit(1);
    }
    queue->data[queue->rear] = val;
    queue->rear = (queue->rear + 1) % LEN;
}
type deQueue(QL *queue)
{
    if (isEmpty(queue))
    {
        puts("empty queue");
        exit(1);
    }
    type temp = queue->data[queue->front];
    queue->front = (queue->front + 1) % LEN;
    return temp;
}
void showQueue(QL *queue)
{
    for (size_t i = 0; i < LEN; i++)
    {
        printf("%c ", queue->data[i]);
    }
    puts("");
}
void clearQueue(QL *queue)
{
    queue->front = queue->rear = 0;
}
void freeQueue(QL **queue)
{
    free(*queue);
    *queue = NULL;
}